﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxUploader.aspx.cs" Inherits="Main_AjaUtils_AjaxUploader" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function ReturnFileNameToDiv() {
            var filePath = GetFileName(document.getElementById('txtFileUploader').value);

            if (filePath == '') {
                DocleanUp();
                return;
            }

            parent.document.getElementById('uploadProgress').style.display = 'inline';
            
            var attatchmentDivID = document.getElementById('txtReturnDiv').value;
            var attatchmentDiv = parent.document.getElementById(attatchmentDivID);
            var fileId = Math.random();
            var fileDiv = '<div id="' + fileId + '"><div class="taskFile">' +
                            filePath +
                            "&nbsp;&nbsp;<span style=\"cursor:pointer\" title=\"Remove Attatchment\" onclick=\"removeAttatchment('" + attatchmentDivID + "','" + fileId + "');\">x</span>" +
                             '</div><br/></div>';
            attatchmentDiv.innerHTML += fileDiv;

            document.getElementById('btnUpload').click();
        }
        
        function GetFileName(filePath) {
            filePath = filePath.substring(filePath.lastIndexOf("\\") + 1);
            return filePath;
        }

        function UploadSuccess() {
            DocleanUp();
        }


        function DocleanUp() {
            try {
                document.getElementById('txtFileUploader').value = '';
                parent.document.getElementById('uploadProgress').style.display = 'none';
                parent.document.getElementById('btnTaskAttatchmentUpload').disabled = false;
            } catch (ex) {
            }
        }
        
        
        

    </script>
</head>
<body>
    <form id="form1" name="form1" runat="server">
    <div>
        <asp:FileUpload ID="txtFileUploader" runat="server"/>
        <asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click" Text="Upload" />
        <asp:DropDownList ID="ddUploadOperation" runat="server"></asp:DropDownList>
        <asp:TextBox id="txtReturnDiv" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtTaskSession" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>
